Passed
Push — add-failing-tests ( 3ed854 )
by Eric
01:20
created

describe(ꞌutilities.toObjectꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
var utilities = require('../utilities.js');
2
3
describe('utilities.toObject', function() {
4
    describe('failing tests', function() {
5
        it("should fail because the arr parameter is undefined", function() {
6
            expect(utilities.toObject).toThrowError(TypeError);
7
        });
8
9
        it("should fail because the arr parameter is not an Array", function() {
10
            expect(utilities.toObject.bind(null, {})).toThrowError(TypeError);
11
        });
12
13
        it("should fail because the mapBy not of type String and not falsy", function() {
14
            expect(utilities.toObject.bind(null, [], {})).toThrowError(TypeError);
15
        });
16
    });
17
18
    describe('array of primitives toObject', function() {
19
        // test example from README.md
20
        var states = ['Sachsen', 'Sachsen-Anhalt', 'Berlin', 'Hamburg'];
21
        var statesObject = utilities.toObject(states);
22
        // end test example from README.md
23
24
        it("should be able to access object by index", function() {
25
            expect(statesObject[0]).toEqual('Sachsen');
26
        });
27
28
        it("should have 4 keys", function() {
29
            expect(Object.keys(statesObject).length).toEqual(4);
30
        });
31
    });
32
33
    describe('array of objects toObject', function() {
34
        // test example from README.md
35
        var news = [
36
            {
37
                id: 12001,
38
                headline: 'Tiger goes limp',
39
                subHeadline: 'Pulls out after 9 holes'
40
            },{
41
                id: 666,
42
                headline: 'Croc has beef with cow',
43
                subHeadline: ''
44
            },{
45
                id: 1337,
46
                headline: 'Germans wurst at penalties',
47
                subHeadline: 'New stats prove England are better from the spot'
48
            }
49
        ];
50
        var newsObject = utilities.toObject(news, 'id');
51
        // end test example from README.md
52
53
        it("should be able to access object by ID", function() {
54
            expect(newsObject[1337].headline).toEqual('Germans wurst at penalties');
55
        });
56
57
        it("should have 3 keys", function() {
58
            expect(Object.keys(newsObject).length).toEqual(3);
59
        });
60
    });
61
});
62